<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>jQuery Mobile Docs - Select</title>
	<link rel="stylesheet"  href="../../../css/themes/default/jquery.mobile-1.1.1.css" />
	<link rel="stylesheet" href="../../_assets/css/jqm-docs.css"/>
	<script src="../../../js/jquery.js"></script>
	<script src="../../../docs/_assets/js/jqm-docs.js"></script>
	<script src="../../../js/jquery.mobile-1.1.1.js"></script>

</head>
<body>

	<div data-role="page" class="type-interior">

		<div data-role="header" data-theme="f">
		<h1>Select Menus</h1>
		<a href="../../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
		<a href="../../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
	</div><!-- /header -->

	<div data-role="content">
		<div class="content-primary">

		<form action="#" method="get">

			<h2>Select menus</h2>
			
			<ul data-role="controlgroup" data-type="horizontal" class="localnav">
				<li><a href="index.html" data-role="button" data-transition="fade" class="ui-btn-active">Basics</a></li>
				<li><a href="options.html" data-role="button" data-transition="fade">Options</a></li>
				<li><a href="methods.html" data-role="button" data-transition="fade">Methods</a></li>
				<li><a href="events.html" data-role="button" data-transition="fade">Events</a></li>
			</ul>
			
			<p>The select menu is based on a native <code>select</code> element, which is hidden from view and replaced with a custom-styled select button that matches the look and feel of the jQuery Mobile framework. The select menu is ARIA-enabled and keyboard accessible on the desktop as well. View the <a href="../../api/data-attributes.html">data- attribute reference</a> to see all the possible attributes you can add to selects.</p>
			
			<p>By default, the framework leverages the native OS options menu to use with the custom button. When the button is clicked, the native OS menu will open. When a value is selected and the menu closes, the custom button's text is updated to match the selected value. Please note that the framework also offers the possibility of having custom (non-native) select menus; see details at the bottom of this page and on the <a href="custom.html"> custom select menu</a> page.</p>

			<p>To add a select menu to your page, start with a standard <code>select</code> element populated with a set of <code>option</code> elements. Set the <code>for</code> attribute of the <code>label</code> to match the <code>id</code> of the <code>select</code> so they are semantically associated. It's possible to <a href="../docs-forms.html">accessibly hide the label</a> if it's not desired in the page layout, but we require that it is present in the markup for semantic and accessibility reasons.</p>
			
			<p>The framework will find all <code>select</code> elements and automatically enhance them into select menus, no need to apply a <code>data-role</code> attribute. To prevent the automatic enhancement of a select, add  <code>data-role="none"</code> attribute to the <code>select</code>.</p>
			
<pre><code>
&lt;label for=&quot;select-choice-0&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
&lt;select name=&quot;select-choice-0&quot; id=&quot;select-choice-0&quot;&gt;
   &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
   &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
   &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
   &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
&lt;/select&gt;
</code></pre>

			<p>This will produce a basic select menu. The default styles set the width of the input to 100% of the parent container and stacks the label on a separate line.</p>

			<label for="select-choice-0" class="select">Shipping method:</label>
			<select name="select-choice-0" id="select-choice-0">
				<option value="standard">Standard: 7 day</option>
				<option value="rush">Rush: 3 days</option>
				<option value="express">Express: next day</option>
				<option value="overnight">Overnight</option>
			</select>

			<h2>Mini version</h2>

			<p>For a more compact version that is useful in toolbars and tight spaces, add the <code>data-mini="true"</code> attribute to the element to create a <a href="../forms-all-mini.html">mini version</a>. </p>

<pre><code>	
&lt;label for=&quot;select-choice-min&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
&lt;select name=&quot;select-choice-min&quot; id=&quot;select-choice-min&quot; <strong>data-mini=&quot;true&quot;</strong>&gt;
   &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
   &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
   &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
   &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
&lt;/select&gt; 
</code></pre>
			
			<p>This will produce a select that a not as tall as the standard version and has a smaller text size.</p>
			<label for="select-choice-min" class="select">Shipping method:</label>
			<select name="select-choice-min" id="select-choice-min" data-mini="true">
				<option value="standard">Standard: 7 day</option>
				<option value="rush">Rush: 3 days</option>
				<option value="express">Express: next day</option>
				<option value="overnight">Overnight</option>
			</select>

			<h2>Field containers</h2>
			<p>Optionally wrap the selects in a container with the <code>data-role="fieldcontain"</code> attribute to help visually group it in a longer form.</p>
<pre><code>
<strong>&lt;div data-role=&quot;fieldcontain&quot;&gt;
</strong>   &lt;label for=&quot;select-choice-1&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
   &lt;select name=&quot;select-choice-1&quot; id=&quot;select-choice-1&quot;&gt;
      &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
      &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
      &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
      &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
   &lt;/select&gt;
<strong>&lt;/div&gt;
</strong></code></pre>

			<p>The select input is now displayed like this:</p>


<div data-role="fieldcontain">
	<label for="select-choice-1" class="select">Shipping method:</label>
	<select name="select-choice-1" id="select-choice-1">
		<option value="standard">Standard: 7 day</option>
		<option value="rush">Rush: 3 days</option>
		<option value="express">Express: next day</option>
		<option value="overnight">Overnight</option>
	</select>
</div>

<p>An example of a select with a long list of options:</p>

<div data-role="fieldcontain">
	<label for="select-choice-2" class="select">Your state:</label>
	<select name="select-choice-2" id="select-choice-2">
		<option value="AL">Alabama</option>
		<option value="AK">Alaska</option>
		<option value="AZ">Arizona</option>
		<option value="AR">Arkansas</option>
		<option value="CA">California</option>
		<option value="CO">Colorado</option>
		<option value="CT">Connecticut</option>
		<option value="DE">Delaware</option>
		<option value="FL">Florida</option>
		<option value="GA">Georgia</option>
		<option value="HI">Hawaii</option>
		<option value="ID">Idaho</option>
		<option value="IL">Illinois</option>
		<option value="IN">Indiana</option>
		<option value="IA">Iowa</option>
		<option value="KS">Kansas</option>
		<option value="KY">Kentucky</option>
		<option value="LA">Louisiana</option>
		<option value="ME">Maine</option>
		<option value="MD">Maryland</option>
		<option value="MA">Massachusetts</option>
		<option value="MI">Michigan</option>
		<option value="MN">Minnesota</option>
		<option value="MS">Mississippi</option>
		<option value="MO">Missouri</option>
		<option value="MT">Montana</option>
		<option value="NE">Nebraska</option>
		<option value="NV">Nevada</option>
		<option value="NH">New Hampshire</option>
		<option value="NJ">New Jersey</option>
		<option value="NM">New Mexico</option>
		<option value="NY">New York</option>
		<option value="NC">North Carolina</option>
		<option value="ND">North Dakota</option>
		<option value="OH">Ohio</option>
		<option value="OK">Oklahoma</option>
		<option value="OR">Oregon</option>
		<option value="PA">Pennsylvania</option>
		<option value="RI">Rhode Island</option>
		<option value="SC">South Carolina</option>
		<option value="SD">South Dakota</option>
		<option value="TN">Tennessee</option>
		<option value="TX">Texas</option>
		<option value="UT">Utah</option>
		<option value="VT">Vermont</option>
		<option value="VA">Virginia</option>
		<option value="WA">Washington</option>
		<option value="WV">West Virginia</option>
		<option value="WI">Wisconsin</option>
		<option value="WY">Wyoming</option>
	</select>
</div>

<h2>Optgroups</h2>
<p>The following example organizes the options into <code>optgroup</code> elements. Support for this feature in mobile selects is a bit spotty, but is improving.</p>

<div data-role="fieldcontain">
	<label for="select-choice-nc" class="select">Preferred delivery:</label>
	<select name="select-choice-8" id="select-choice-nc">
		<optgroup label="FedEx">
			<option value="firstOvernight">First Overnight</option>
			<option value="expressSaver">Express Saver</option>
			<option value="ground">Ground</option>
		</optgroup>
		<optgroup label="UPS">
			<option value="firstOvernight">First Overnight</option>
			<option value="expressSaver">Express Saver</option>
			<option value="ground">Ground</option>
		</optgroup>
		<optgroup label="US Mail">
			<option value="standard">Standard: 7 day</option>
			<option value="rush">Rush: 3 days</option>
			<option value="express">Express: next day (disabled)</option>
			<option value="overnight">Overnight</option>
		</optgroup>
	</select>
</div>



<h2>Vertically grouped select inputs</h2>

<p>To create a grouped set of select inputs, first add <code>select</code> and a corresponding <code>label</code>. Set the <code>for</code> attribute of the <code>label</code> to match the <code>id</code> of the <code>select</code> so they are semantically associated.</p>

<p>Because the <code>label</code> element will be associated with each individual select input, we recommend wrapping the selects in a <code>fieldset</code> element that has a <code>legend</code> which acts as the combined label for the grouped inputs.</p>

<p>Lastly, one needs to wrap the <code>fieldset</code> in a <code>div</code> with <code> data-role="controlgroup"</code> attribute, so it can be styled as a group.</p>
			
<pre><code>	
&lt;div data-role=&quot;fieldcontain&quot;&gt;
&lt;fieldset data-role=&quot;controlgroup&quot;&gt;
	&lt;legend&gt;Date of Birth:&lt;/legend&gt;

    &lt;label for="select-choice-month">Month&lt;/label&gt;
&lt;select name="select-choice-month" id="select-choice-month"&gt;
	&lt;option&gt;Month&lt;/option&gt;
	&lt;option value="jan"&gt;January&lt;/option&gt;
	&lt;!-- etc. --&gt;
&lt;/select&gt;

	&lt;label for="select-choice-day">Day&lt;/label&gt;
&lt;select name="select-choice-day" id="select-choice-day"&gt;
	&lt;option&gt;Day&lt;/option&gt;
	&lt;option value="1"&gt;1&lt;/option&gt;
	&lt;!-- etc. --&gt;
&lt;/select&gt;

&lt;label for="select-choice-year">Year&lt;/label&gt;
&lt;select name="select-choice-year" id="select-choice-year"&gt;
	&lt;option&gt;Year&lt;/option&gt;
	&lt;option value="2011"&gt;2011&lt;/option&gt;
	&lt;!-- etc. --&gt;
&lt;/select&gt;
&lt;/fieldset&gt;
&lt;/div&gt;
</code></pre>

	<div data-role="fieldcontain">
	<fieldset data-role="controlgroup">
		<legend>Date of Birth:</legend>
		
		<label for="select-choice-month">Month</label>
		<select name="select-choice-month" id="select-choice-month">
			<option>Month</option>
			<option value="jan">January</option>
			<option value="dec">December</option>
			<option value="feb">February</option>
			<option value="mar">March</option>
			<option value="apr">April</option>
			<option value="may">May</option>
			<option value="jun">June</option>
			<option value="jul">July</option>
			<option value="aug">August</option>
			<option value="sep">September</option>
			<option value="oct">October</option>
			<option value="nov">November</option>
			<option value="dec">December</option>
		</select>

		<label for="select-choice-day">Day</label>
		<select name="select-choice-day" id="select-choice-day">
			<option>Day</option>
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
			<option value="5">5</option>
			<option value="6">6</option>
			<option value="7">7</option>
		</select>

		<label for="select-choice-year">Year</label>
		<select name="select-choice-year" id="select-choice-year">
			<option>Year</option>
			<option value="2011">2011</option>
			<option value="2010">2010</option>
			<option value="2009">2009</option>
			<option value="2008">2008</option>
			<option value="2007">2007</option>
			<option value="2006">2006</option>
			<option value="2005">2005</option>
			<option value="2004">2004</option>
		</select>
	</fieldset>

</div>

<h2>Horizontally grouped select inputs</h2>
<p>Select inputs can also be used for grouped sets with more than one related selections. To make a horizontal button set, add the <code>data-type="horizontal"</code> to the fieldset. Note that the buttons which trigger the select will resize depending on the currently selected option’s value. Note that browsers without support for <code>display: inline-block;</code> will group the selects vertically, as above.</p>

<code>
&lt;fieldset data-role="controlgroup" <strong>data-type="horizontal"</strong>&gt;
</code>

	<fieldset data-role="controlgroup" data-type="horizontal">
		<legend>Date of Birth:</legend>
		
		<label for="select-choice-month">Month</label>
		<select name="select-choice-month" id="select-choice-month">
			<option value="jan">Jan</option>
			<option value="dec">Dec</option>
			<option value="feb">Feb</option>
			<option value="mar">Mar</option>
			<option value="apr">Apr</option>
			<option value="may">May</option>
			<option value="jun">Jun</option>
			<option value="jul">Jul</option>
			<option value="aug">Aug</option>
			<option value="sep">Sep</option>
			<option value="oct">Oct</option>
			<option value="nov">Nov</option>
			<option value="dec">Dec</option>
		</select>

		<label for="select-choice-day">Day</label>
		<select name="select-choice-day" id="select-choice-day">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
			<option value="5">5</option>
			<option value="6">6</option>
			<option value="7">7</option>
			<option value="8">8</option>
			<option value="9">9</option>
			<option value="10">10</option>
			<option value="11">11</option>
			<option value="12">13</option>
			<option value="13">14</option>
			<option value="15">15</option>
		</select>

		<label for="select-choice-year">Year</label>
		<select name="select-choice-year" id="select-choice-year">
			<option value="2011">2012</option>
			<option value="2011">2011</option>
			<option value="2010">2010</option>
			<option value="2009">2009</option>
			<option value="2008">2008</option>
			<option value="2007">2007</option>
			<option value="2006">2006</option>
			<option value="2005">2005</option>
			<option value="2004">2004</option>
		</select>
	</fieldset>
        
<h2>Calling the select menu plugin</h2>
<p>The select menu plugin will auto initialize on any page that contains a select menu, without any need for a <code>data-role</code> attribute in the markup. However, you can directly call the select menu plugin on any selector, just like any normal jQuery plugin:</p>
<pre><code>
$('select').selectmenu();			
</code></pre>
    
	</form>
	
	
	<h2>Theming selects</h2>
	<p>You can specify any jQuery Mobile button <code>data-</code> attribute on a select element, too. In this example, we're setting the theme, icon and inline properties:</p>

	<div data-role="fieldcontain">
		<label for="select-choice-11" class="select">Actions</label>
		<select name="select-choice-11" id="select-choice-11" data-theme="e" data-icon="gear" data-inline="true">
			<option value="view">User details</option>
			<option value="edit">Edit user</option>
			<option value="deactivate">De-activate</option>
			<option value="delete">Delete user</option>
		</select>
	</div>
    
	
	<h2>Custom select menus</h2>
	<p>For the sake of advanced styling, the framework also offers a method of generating <a href="custom.html">custom menus</a> from existing select menu markup  instead of the native OS menu. The custom menu supports disabled options and multiple selection (whereas native mobile OS support for both is inconsistent), adds an elegant way to handle placeholder values, and restores missing functionality on certain platforms such as <code>optgroup</code> support on Android.
		
	<div align="right"><a href="custom.html" data-role="button" data-icon="arrow-r" data-iconpos="right" data-inline="true" align="right">Custom select menu docs</a>
</div>
		</p>
	
	</div><!--/content-primary -->		
	
	<div class="content-secondary">
		
		<div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
			
				<h3>More in this section</h3>
				
				<ul data-role="listview" data-theme="c" data-dividertheme="d">
				
					<li data-role="list-divider">Form elements</li>
					<li><a href="../docs-forms.html">Form basics</a></li>
					<li><a href="../forms-all.html">Form element gallery</a></li>
					<li><a href="../forms-all-mini.html">Mini form element gallery</a></li>
					<li><a href="../textinputs/index.html">Text inputs</a></li>
					<li><a href="../search/">Search input</a></li>
					<li><a href="../slider/">Slider</a></li>
					<li><a href="../switch/">Flip toggle switch</a></li>
					<li><a href="../radiobuttons/">Radio buttons</a></li>
					<li><a href="../checkboxes/">Checkboxes</a></li>
					<li data-theme="a"><a href="index.html">Select menus</a></li>
					<li><a href="../forms-themes.html">Theming forms</a></li>
					<li><a href="../forms-all-native.html">Native form elements</a></li>
					<li><a href="../forms-sample.html">Submitting forms</a></li>
					
	
				</ul>
		</div>
	</div>		

</div><!-- /content -->

<div data-role="footer" class="footer-docs" data-theme="c">
		<p>&copy; 2012 jQuery Foundation and other contributors</p>
</div>
	
</div><!-- /page -->

</body>
</html>

